;
define(["MComponent"], function(MComponent) {
	/**
	 * 过渡包装器
	 * @param {Object} background 背景
	 */
	var MWIETransition = function(background) {
		this.dom = this.query("<div></div>", "MWIETransition");
		this.setBackground(background);
		
		/**
		 * 是否销毁
		 */
		var isDestroy = false;
		
		/**
		 * IE浏览器检测标志
		 */
		var ieFlag = true;

		/**
		 * 动画是否已启动
		 */
		var isStart = false;
		
		/**
		 * 注册过渡属性
		 */
		this.transition = function(array, ms) {
			this.setTransition(this, array, ms);
			//			this.start();
		};
		
		/**
		 * IE动画完成后的回调
		 */
		this.ieOnSuccess = function(func){
			if(func && typeof func == 'function'){
				this.success = func;
			}
		}
		
		/**
		 * 为指定元素添加过渡属性
		 */
		this.setTransition = function(dom, array, ms) {
			ieFlag = false;
			dom.mt = {};
			dom.mt.animate = {};
			dom.setStyle = function(nkey, val) {
				var flag = false;
				for(var key in array) {
					if(nkey == array[key]) {
						flag = true;
						break;
					} 
				}
				if(flag){
					dom.mt.animate[nkey] = val;
					var ie = function(){
						dom.mt.animate[nkey] = val;
						ieFlag = true;
					};
					mofum.ieCallback(ie, ie, ie, ie, ie);
				}else{
					dom.dom.css(nkey, val);
				}
				if(!ieFlag){
					dom.dom.css(nkey, val);
				}
				return dom;
			}
			var ie6 = function() {
				dom["start"] = function() {
					var $dom = dom.dom;
					$dom.stop(true, false);
					$dom.animate(dom.mt.animate, ms, function() {
						if(dom.success){
							dom.success();
						}
					});
					return dom;
				}
				ieFlag = true;
			}
			mofum.ieCallback(ie6, ie6, ie6, ie6, ie6);

			if(!ieFlag) {
				var valKey = "";
				var buffer = [];
				for(var key in array) {
					buffer.push(array[key] + " " + (ms / 1000) + "s linear");
				}

				valKey = buffer.join(",");
				dom.setStyle("transition", valKey);
				dom.setStyle("-ms-transition", valKey);
				dom.setStyle("-moz-transition", valKey);
				dom.setStyle("-webkit-transition", valKey);
				dom.setStyle("-o-transition", valKey);

				dom["start"] = function() {
					for(var key in dom.mt.animate) {
						dom.setStyle(key, dom.mt.animate[key]);
					}
					return dom;
				}
			}
		}
		
		/**
		 * 销毁过渡效果
		 */
		this.destroy = function() {
			dom.dom.stop(true, true);
		}
		
		/**
		 * 销毁过渡效果
		 */
		this.start = function() {
			//
		}

		this.init();
	};

	/**
	 * 销毁过渡效果
	 * @param {Object} dom
	 */
	MWIETransition.destroy = function(dom) {
		if(dom instanceof MComponent) {
			dom.setStyle("transition", "");
			dom.destroy();
		}
	};
	mofum.extend(MWIETransition, MComponent);
	return MWIETransition;
});